package com.smashcrush.client.gwt.client.editor;


import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.smashcrush.client.gwt.util.WidgetUtil;
import com.smashcrush.model.Script;

public class ScriptsSpace extends Composite {

	SimplePanel panel;
	
	ScriptScrollTable table;

	public ScriptsSpace() {

		panel = new SimplePanel();
		panel.setSize("100%", "100%");

		table = new ScriptScrollTable();
		table.addRowSelectionHandler(new RowSelectionHandler() {

			@Override
			public void onRowSelection(RowSelectionEvent event) {
				edit(table.getSelected());
			}
		});

		search();

		initWidget(panel);
	}

	public void search() {
		table.reset();
		setCenter(table);
	}

	public void edit(Script script) {
		setCenter(new ScriptEditor(script));
	}

	void setCenter(Widget w) {
		panel.setWidget(WidgetUtil.decorate(w, "80%", "70%"));
	}

}
